package com.srd.phone.activity;

import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.shengrongdai.srd.R;

/**
 * 轮播界面
 */
public class CarouselActivity extends BaseActivity {

    private String url;
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        url = getIntent().getStringExtra("url");
        setContentView(R.layout.activity_carousel);
        initView();
    }

    @Override
    public void initView() {
        super.initView();
        tv_common_title.setText("标题");
        configWebView();
    }

    private void configWebView() {
        webView = (WebView) findViewById(R.id.wv);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
        webView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {
                super.onProgressChanged(view, newProgress);
                if (newProgress == 0) {
                    showWaitingDialog();
                } else if (newProgress == 100) {
                    cancelWaitingDialog();
                }
            }
        });
        WebSettings ws = webView.getSettings();
        ws.setJavaScriptEnabled(true);
        ws.setBlockNetworkImage(false);
        webView.requestFocus();

        webView.loadUrl(url);
    }
}
